package com.jk.controller;


import cn.hutool.core.util.URLUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName HttpRequestController
 * @Descripttion TODO
 * @Author DELL
 * @Date 2022/10/24 9:17
 * @Version 0.001
 */
@Slf4j
@RestController
@RequestMapping("http")
public class HttpRequestController {


    /**
    * @Author: binzi
    * @Description:调用机器人接口(智能机器人回复调用青云客)
    * @Date: 2022/10/24 9:41
    * @Return: java.lang.String
    **/
    @RequestMapping("aiReply")
    public  String aiReply(String content){
        String body = HttpRequest.get("http://api.qingyunke.com/api.php?key=free&appid=0&msg="+ URLUtil.encode(content))
                .execute().charset("utf-8").body();
        JSONObject jsonObject = JSONUtil.parseObj(body);
        if (jsonObject.getStr("result").equals("0")) {
            return jsonObject.getStr("content");
        }else {
            return "操作频繁！！！";
        }
    }
//

}
